package cn.com.klun.tjy.common.util;


import java.math.BigDecimal;
import java.text.DecimalFormat;

public class MoneyFormatUtils {
    public MoneyFormatUtils() {
    }

    public static String format(String value, String formatStyle, String formatType) {
        DecimalFormat df = new DecimalFormat();
        BigDecimal baseNum = new BigDecimal(100);
        BigDecimal bg = new BigDecimal(value);
        if ("f2y".equals(formatType)) {
            bg = bg.divide(baseNum);
        } else if ("y2f".equals(formatType)) {
            bg = bg.multiply(baseNum);
        }

        df.applyPattern(formatStyle);
        return df.format(bg);
    }

    public static String format(BigDecimal value, String formatStyle, String formatType) {
        DecimalFormat df = new DecimalFormat();
        BigDecimal baseNum = new BigDecimal(100);
        if ("f2y".equals(formatType)) {
            value = value.divide(baseNum);
        } else if ("y2f".equals(formatType)) {
            value = value.multiply(baseNum);
        }

        df.applyPattern(formatStyle);
        return df.format(value);
    }
}
